//
//  WDLinkMessageCell.m
//  通讯录Demo
//
//  Created by 王笛 on 2016/12/6.
//  Copyright © 2016年 王笛. All rights reserved.
//

#import "WDLinkMessageCell.h"
#import "WDLinkMessage.h"
#import "UIColor+WDColorExtension.h"

@interface WDLinkMessageCell ()
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *cityLabel;
@property (weak, nonatomic) IBOutlet UILabel *jobLabel;

@end

@implementation WDLinkMessageCell

+ (instancetype)linkMessageCellWithTableView:(UITableView *)tableView
{
    NSString *ID = @"linkMessageCell";
    
    WDLinkMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] lastObject];
    }
    
    return cell;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.cityLabel.layer.cornerRadius = 2;
    self.cityLabel.clipsToBounds = YES;
    
    self.iconView.contentMode = UIViewContentModeScaleAspectFit;
}

- (void)setLinkMessage:(WDLinkMessage *)linkMessage
{
    _linkMessage = linkMessage;
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:linkMessage.image_url] placeholderImage:[UIImage imageNamed:@"defaultIcon"]];
    self.nameLabel.text = _linkMessage.name;
    self.cityLabel.text = _linkMessage.work_city_name;
    self.cityLabel.backgroundColor = [UIColor getColorFromString:linkMessage.work_city_color];
    self.jobLabel.text = _linkMessage.position_desc;
}

@end
